package com.jsy.common.util.bytecode;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class AsmBytecodeModifier {
    public static void main(String[] args) throws IOException {
//        Path inputPath = Paths.get("path/to/input/MyClass.class");
        Path inputPath = Paths.get("F:\\jsy\\goalong\\goalong-common\\src\\main\\lib\\h.class");
        byte[] bytecode = Files.readAllBytes(inputPath);

        ClassReader classReader = new ClassReader(bytecode);
        ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
        ClassVisitor classVisitor = new MyClassVisitor(classWriter);

        classReader.accept(classVisitor, ClassReader.SKIP_DEBUG);

        byte[] modifiedBytecode = classWriter.toByteArray();

//        Path outputPath = Paths.get("path/to/output/MyModifiedClass.class");
        Path outputPath = Paths.get("F:\\jsy\\goalong\\goalong-common\\src\\main\\lib\\h2.class");
        Files.write(outputPath, modifiedBytecode);
    }
}